package sdk.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.Contract;
import model.RewAndPun;
import sdk.service.ContractManager;
import sdk.service.DutyManager;
import sdk.service.EmpManager;
import sdk.service.RewAndPunManager;
import sdk.service.RewAndPunTypeManager;

public class UpdateRewAndPunServlet extends HttpServlet {

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			this.doPost(request, response);
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		RewAndPun rap = new RewAndPun();
		rap.setId(Integer.parseInt(request.getParameter("id")));
		rap.setTitle(request.getParameter("title"));
		
		EmpManager emp = new EmpManager();
		rap.setEmp(emp.getById(Integer.parseInt(request.getParameter("empid"))));
		
		RewAndPunTypeManager rapt = new RewAndPunTypeManager(); 
		rap.setRewAndPunType(rapt.getById(Integer.parseInt(request.getParameter("rewAndPunType"))));
		
		try {
			rap.setTime(new SimpleDateFormat("yyyy-MM-dd").parse(request.getParameter("time")));
			
		} catch (ParseException e) {
			e.printStackTrace();
		}
		rap.setContent(request.getParameter("content"));
		rap.setMoney(Double.parseDouble(request.getParameter("money")));
		
		RewAndPunManager rapm = new RewAndPunManager();
		rapm.update(rap);
		request.getRequestDispatcher("/FindRewAndPunServlet").forward(request,response);
	}

}
